<!--探索课程 -->
<template>
  <div>
    <course-detail
      v-if="showDetail && courseInfoId"
      :courseInfoId="courseInfoId"
      @changeShowDetail="changeShowDetail"
    ></course-detail>
    <div v-else>
      <el-form
        :inline="true"
        :model="dataForm"
        label-width="80px"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            v-model="dataForm.searchCourse"
            placeholder="课程名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.searchTeacher"
            placeholder="老师名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getDataList()">搜索</el-button>
        </el-form-item>
      </el-form>
      <div v-if="dataList.length > 0">
        <!-- 数据列表 -->
        <div v-for="(item, index) in dataList" :key="index" class="dataList">
          <el-row>
            <el-col :span="6"><img :src="item.cover_picture" /></el-col>
            <el-col :span="18">
              <div class="content">
                <div class="item1">
                  <span>{{ item.course_name }}</span>
                  <span>{{ item.publish_time }}</span>
                </div>
                <div class="item2">课程简介：{{ item.course_intro }}</div>
                <div class="item3">
                  <div>教师名称：{{ item.teacher_name }}</div>
                  <div>
                    <el-button
                      style="color: skyblue"
                      @click="getCourseId(item.course_info_id)"
                      >了解更多</el-button
                    >
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
      <div v-else>
        <img :src="noData" alt="" style="height:400px;width:600px">
      </div>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
        class="pagination"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import CourseDetail from "./course-detail.vue";
export default {
  components: { CourseDetail },
  data() {
    return {
      showDetail: false,
      dataForm: {
        searchCourse: "",
        searchTeacher: "",
      },
      dataList: [],
      pageIndex: 1,
      totalPage: 0,
      pageSize: 10,
      courseInfoId: "",
      noData:require('@/assets/img/noData.jpg')
    };
  },
  created() {
    this.getDataList();
  },
  methods: {
    //获得数据
    getDataList() {
      this.$http({
        url: this.$http.adornUrl("/stu/explore/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          searchCourse: this.dataForm.searchCourse,
          searchTeacher: this.dataForm.searchTeacher,
        }),
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.$message(data.msg);
          this.dataList = [];
          this.totalPage = 0;
        }
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },

    //获得点击课程的id
    getCourseId(param) {
      this.courseInfoId = param;
      console.log(param);
      this.showDetail = true;
    },

    //改变showDetail
    changeShowDetail() {
      this.showDetail = false;
    },
  },
};
</script>

<style  scoped>
.dataList {
  height: 124px;
  width: 80%;
}
.dataList img {
  height: 120px;
  width: 100%;
}
.content {
  border: 1px solid silver;
  padding: 10px;
}
.content .item1,
.item3 {
  display: flex;
  justify-content: space-between;
}
.item1 span:nth-child(1) {
  font-size: 17px;
}
.item1 span:nth-child(2) {
  margin: auto 10px;
}
.item2 {
  overflow: hidden;
  margin: 15px auto;
  height: 15px;
}
.item3 div:nth-child(1) {
  margin: auto 0px;
}
.button {
  padding: 0;
  float: right;
}
.pagination {
  position: absolute;
  bottom: 50px;
  right: 100px;
}
</style>
